nodeprojectpath="/Users/zgw/code/nodepro/htprov5"
tomcat10path="/Users/zgw/code/java/htprov4"
mvnpath="/Users/zgw/code/maven/apache-maven-3.9.7/bin/"

dockerwebappspath="/Users/zgw/code/docker/tomcat10/webapps"
IMAGE_NAME=tomcat
IMAGE_TAG=10.1.24-jre17
CONTAINER_NAME=tomcat10meeting

cd $nodeprojectpath
npm run build

cd $tomcat10path

$mvnpath/mvn  clean
$mvnpath/mvn  package



# 检查容器是否存在
if [ $(docker ps -a -q -f name=${CONTAINER_NAME}) ]; then
    # 停止并删除现有的容器
    docker stop ${CONTAINER_NAME}
    docker rm ${CONTAINER_NAME}
else
    echo "容器 ${CONTAINER_NAME} 已经存在。"
fi


rm -f $dockerwebappspath/meeting.war
cp  target/meeting.war $dockerwebappspath



# 检查镜像是否存在
if ! docker image inspect ${IMAGE_NAME}:${IMAGE_TAG} > /dev/null 2>&1; then
    echo "镜像 ${IMAGE_NAME}:${IMAGE_TAG} 不存在，开始 pull..."
    docker pull ${IMAGE_NAME}:${IMAGE_TAG}
else
    echo "镜像 ${IMAGE_NAME}:${IMAGE_TAG} 已经存在，不需要 pull。"
fi
#docker pull tomcat:10.1.24-jre17





docker run -d -p 38080:8080 --restart=always --name ${CONTAINER_NAME} -v /Users/zgw/code/docker/tomcat10/webapps:/usr/local/tomcat/webapps tomcat:10.1.24-jre17

scp -r $dockerwebappspath/meeting.war root@8.138.57.68:/root/webapps

#docker run -d -p 58080:8080 --restart=always --name meeting -v /root/webapps:/usr/local/tomcat/webapps tomcat:10.1.24-jre17